<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<base href="<%=basePath%>">
<title>总部</title>
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/css/bootstrap.min.css">
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/css/main.css">
<script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/js/main.js"></script>
<script src="http://cdn.bootcss.com/angular.js/1.4.5/angular.min.js"></script>
<script src="${pageContext.request.contextPath}/js/MD5.js"></script>

</head>
<body>
	<%@ include file="header.jsp"%>
	<%@ include file="left.jsp"%>
	<div id="index"
		style="position: absolute;left: 180px;top: 80px;bottom: 0;right: 0;">
		<section id="main">
			<div class="scrollbar1-1" id="style1-1">
				<div class="main_div">
					<div class="main_title">
						<span>分销佣金设置</span>
					</div>
					<form class="form-horizontal" style="margin-top: 60px">

						<!--  	<div class="form-group ">
							<label class="col-xs-2 control-label" style="text-align: right">佣金提成方式
							</label>
							<div class="col-xs-2">
								<label class="radio-inline"> <input type="radio"
									name="inlineRadioOptions" id="inlineRadio1" value="1"
									onclick="ck(this)" checked> 百分比佣金
								</label> <label class="radio-inline"> <input type="radio"
									name="inlineRadioOptions" id="inlineRadio2" value="2"
									onclick="ck(this)"> 固定佣金
								</label>
							</div>
						</div>-->
						<div class="form-group" id="percentInput">
							<label class="col-xs-2 control-label" style="text-align: right">一级分销佣金
							</label>
							<div class="col-xs-2">
								<input type="number" id="oneLevel"
									oninput="if(value.length>5)value=value.slice(0,5)"
									class="form-control" placeholder="请输入一级分销佣金">
							</div>
							<label class="col-xs-2 control-label" style="text-align: left">%
							</label>
						</div>
						<!--<div class="form-group" id="moneyInput" >
							<label class="col-xs-2 control-label" style="text-align: right">固定提成金额
							</label>
							<div class="col-xs-2">
								<input type="number" id="fixedMoney"
									oninput="if(value.length>5)value=value.slice(0,5)"
									class="form-control" placeholder="请输入固定提成金额">
							</div>
							<label class="col-xs-2 control-label" style="text-align: left">￥
							</label>
						</div>-->
						<div class="form-group">
							<label class="col-xs-2 control-label" style="text-align: right">二级分销佣金</label>
							<div class="col-xs-2">
								<input type="number" id="twoLevel"
									oninput="if(value.length>6)value=value.slice(0,6)"
									class="form-control" placeholder="请输入二级分销佣金">
							</div>
							<label class="col-xs-4 control-label" style="text-align: left">%
								(注意！一级分销与二级分销百分比之和必须等于100)</label>
						</div>
						<div class="form-group" style="display:none">
							<label class="col-xs-2 control-label" style="text-align: right">三级分销佣金</label>
							<div class="col-xs-2">
								<input type="number" id="threeLevel"
									oninput="if(value.length>6)value=value.slice(0,6)"
									class="form-control" placeholder="请输入三级分销佣金">
							</div>
							<label class="col-xs-2 control-label" style="text-align: left">%</label>
						</div>
						<div class="form-group">
							<label class="col-xs-2 control-label" style="text-align: right">返点价格区间</label>
							<div class="col-xs-1">
								<input type="number" id="lowMoney"
									oninput="if(value.length>6)value=value.slice(0,6)"
									class="form-control" placeholder="最低价格">
							</div>
							<label class="col-xs-1 control-label"
								style="text-align: left;width:45px">—</label>
							<div class="col-xs-1">
								<input type="number" id="hightMoney"
									oninput="if(value.length>6)value=value.slice(0,6)"
									class="form-control" placeholder="最高价格">
							</div>
						</div>
						<div class="form-group">
							<div class="col-xs-4 col-xs-offset-2">
								<button type="button" class="col-xs-6 btn btn-primary"
									onclick="submitSet()">点此设置</button>
							</div>
						</div>
					</form>
				</div>
			</div>
		</section>
	</div>
	<script>
		var drawType = 0;
		var gldoneLevel = 0;
		var gldrated = 0;
		$(function() {
			///	$("#moneyInput").hide();
			$.post(urls + "utilAction/getCommission",
				function(res) {
					if (res) {
						console.log(res);
						gldoneLevel = res.oneLevel;
						gldrated = res.rated;
						$("#oneLevel").val(res.oneLevel);
						$("#twoLevel").val(res.twoLevel);
						$("#threeLevel").val(res.threeLevel);
						$("#lowMoney").val(res.brokerageMin);
						$("#hightMoney").val(res.brokerageMax);
						$("#fixedMoney").val(res.rated);
						if (res.type == 0) {
							//$("#inlineRadio1").attr('checked', 'checked');
							//	$("#percentInput").show();
							//	$("#moneyInput").hide();
						} else {
							//	$("#inlineRadio2").attr('checked', 'checked');
							//$("#moneyInput").show();
							//$("#percentInput").hide();
						}
					}
				}
			)
		})
		function submitSet() {
			var fixedMoney = parseFloat($("#fixedMoney").val())
			var oneLevel = parseFloat($("#oneLevel").val());
			var twoLevel = parseFloat($("#twoLevel").val());
	
			//	var twoLevel = parseFloat($("#twoLevel").val());
			//	var threeLevel = parseFloat($("#threeLevel").val());
			var lowMoney = parseFloat($("#lowMoney").val());
			var hightMoney = parseFloat($("#hightMoney").val());
			var index = $("#oneLevel").val().indexOf(".")
			if (index > 0) {
				alert("分销比例不能包含小数点");
				return;
			}
			var index2 = $("#twoLevel").val().indexOf(".")
			if (index2 > 0) {
				alert("分销比例不能包含小数点");
				return;
			}
			if((twoLevel+oneLevel)!=100){
			alert("一级分销与二级分销百分比之和必须等于100");
				return;			
			}
			if (drawType == 0) {
				if (oneLevel && lowMoney && hightMoney) {
					gldoneLevel = oneLevel;
					$.post(urls + "utilAction/updateCommission",
						{
							id : 1,
							oneLevel : oneLevel,
							twoLevel : twoLevel,
							brokerageMin : lowMoney,
							brokerageMax : hightMoney,
							type : 0,
						},
						function(data) {
							if (data) {
								alert("设置成功");
							} else {
								alert("设置失败")
							}
						})
				} else {
					alert("请填写完整信息")
				}
			} else {
				if (fixedMoney && lowMoney && hightMoney) {
					gldrated = fixedMoney;
					$.post(urls + "utilAction/updateCommission",
						{
							id : 1,
							rated : fixedMoney,
							brokerageMin : lowMoney,
							brokerageMax : hightMoney,
							type : 1,
							oneLevel : gldoneLevel
						},
						function(data) {
							if (data) {
								alert("设置成功");
							} else {
								alert("设置失败")
							}
						})
				} else {
					alert("请填写完整信息")
				}
			}
	
		}
		function ck(obj) {
			if ($(obj).val() == '1') {
				$("#percentInput").show();
				$("#moneyInput").hide();
				drawType = 0;
			} else if ($(obj).val() == '2') {
				$("#moneyInput").show();
				$("#percentInput").hide();
				drawType = 1;
			}
	
		}
	</script>
</body>
</html>